package com.alex.controller;

import cn.hutool.http.HttpUtil;
import com.alex.entityVo.ArticleSearchVo;
import com.alex.sevice.StaticService;
import com.alibaba.fastjson.JSONObject;
import common.beans.User;
import common.util.PmidUtils;
import common.util.UserUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/topic_idea_assistant")
@RestController
@Tag(name = "高分选题")
public class TopicsIdeaAssistantController {


    public static String RESTURL_ES = "http://10.1.1.11:29000";

    @Resource
    StaticService staticService;


    @Operation(summary = "检索", description = "第一个筛选, 输入检索词, 返回左侧文章列表")
    @PostMapping(value = "search")
    public String search(@RequestBody ArticleSearchVo articleSearchVo) {


        staticService.insStat(articleSearchVo.getPram(), "检索");

        User user = UserUtil.getUserUnloginDeniey();
        articleSearchVo.setUid(user.getUid());
        articleSearchVo.setGid(user.getGid());
        articleSearchVo.setRealName(user.getRealname());
        return HttpUtil.post(RESTURL_ES + "/search/search", JSONObject.toJSONString(articleSearchVo));
    }

    @Operation(summary = "根据检索结果返回的 UUID 来生成柱状图", description = "")
    @GetMapping(value = "chart_bar")
    public String chart_bar(String uuid, String chartType, String count) {
        Map<String, Object> map = new HashMap<>();
        map.put("uuid", uuid);
        map.put("type", chartType);
        map.put("count", count);
        System.out.println("uuid:" + uuid);
        System.out.println("chartType:" + chartType);
        return HttpUtil.post(RESTURL_ES + "/search/chart_bar", map);
    }

    @Operation(summary = "根据检索结果返回的 UUID 来生成热力图", description = "")
    @GetMapping(value = "hot")
    public String hot(String uuid, String chart) {
        Map<String, Object> map = new HashMap<>();
        map.put("uuid", uuid);
        map.put("chart", chart);
        System.out.println("uuid:" + uuid);
        System.out.println("chart:" + chart);
        return HttpUtil.get(RESTURL_ES + "/search/hot", map);
    }


    @Operation(summary = "返回首页关系图", description = "基因,通路,疾病,药物的互相关系图")
    @GetMapping(value = "index_chart_bar")
    public String index_chart_bar(String uuid, String chart) {
        Map<String, Object> map = new HashMap<>();
        map.put("uuid", uuid);
        map.put("chart", chart);
        System.out.println("uuid:" + uuid);
        System.out.println("chart:" + chart);
        return HttpUtil.post(RESTURL_ES + "/topic_idea_assistant/topic_idea_assistant", map);
    }

    @GetMapping("trans")
    public String translate(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        return HttpUtil.post(RESTURL_ES + "/cn_pubmed/translate", map);
    }

}
